{include file="public/header" /}
<style type="text/css">
    #des, #des input {
        width: 40px;
        text-align: center;
    }

    #id {
        width: 78px;
    }

    .bs-checkbox {
        width: 36px;
        height: 40px
    }

    .fixed-table-toolbar .columns, .fixed-table-toolbar .search {
        margin-left: 0px;
        margin-top: 0px
    }

    #title span {
        float: right;
    }

    .btn-active {
        background: #1ab394;
        color: #fff
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        {include file="public/tophead"}
        {include file="public/top" /}
        <div class="ibox-content">
            <div class="row row-lg">

                <div style="display:block;clear: both;"></div>
                <div class="fixed-table-toolbar">

                </div>
                <div class="example">
                    <form class="form-horizontal" method="post">
                        <table id="table_area" data-toggle="table" data-striped="false">
                            <thead>
                            <tr>

                                <th >名称</th>
                                <th>名称首字母</th>
                                <th>热门</th>
                                <th>显示</th>
                                <th>管理</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}

                            <tr id="id_{$vo.id}" class="class_0">
                                <td class="categoryTitle"><span class="space"></span><span style="cursor:pointer" onclick="op(this,{$vo.id})">[+]</span>{$vo.name}</td>
                                <td>{$vo.first_char}</td>
                                <td>{if $vo.is_hot}是{else}否{/if}</td>
                                <td>{if $vo.is_show}是{else}否{/if}</td>
                                <td>
                                    <div class="btn-group">
                                        <div data-toggle="dropdown" class="btn btn-primary btn-xs dropdown-toggle">
                                            操作 <span class="caret"></span>
                                        </div>
                                        <ul class="dropdown-menu">
                                            <li>
                                                <a onClick="add('{:url('Area/areaAdd',['id'=>$vo['id'],'url'=>-1])}')">修改</a>
                                            </li>
                                            <li class="divider"></li>
                                            <li><a onclick="del('{$vo.id}')">删除</a></li>
                                        </ul>
                                    </div>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>



        </div>
    </div>
</div>
{include file="public/footer" /}
{load href="__STYLE__/admin/plugins/bootstrap/bootstrap-table.min.css"}
{load href="__STYLE__/admin/plugins/bootstrap/bootstrap-table.min.js"}
{load href="__STYLE__/admin/plugins/bootstrap/bootstrap-table-zh-CN.min.js"}
<script type="text/javascript">
    function add(url) {
        layer.open({
            type: 2,
            title: '内容管理',
            shadeClose: false,
            shade: 0.2,
            area: ['80%', '95%'],
            skin: 'shangchuantup',
            // shift:-1,
            content: url,
        });
    }


</script>

<script>
    function op(object,pid) {
        var tr_object= $(object).parent().parent();

        if ($(object).text() == "[+]") {
            $(object).text("[-]");

            if( $('tr').hasClass('class_'+pid)){
                $('.class_'+pid).show();
                return;
            }

            $.ajax({
                url: "{:url('area/getArea')}",
                type: 'POST',
                dataType: 'JSON',
                data: {pid: pid},
                success: function (res) {
                    var json=eval("("+res+")")
                    if (json.status == 1) {
                        var data = json.data;
                        var html='';
                        var new_class = tr_object.attr('class')+' class_'+pid;
                        $(data).each(function (index,value) {
                            var url='{:url('Area/areaAdd')}';
                            var add_url=url+'?id='+value.id+"&url=-1";
                            var is_hot= value.is_hot==1?"是":"否";
                            var is_show= value.is_show==1?"是":"否";
                            var space = $(object).parent().children(".space").html()+"&nbsp;&nbsp;&nbsp;&nbsp;";
                            html +='<tr id="id_'+value.id+'" class="'+new_class+'">\n' +
                                '                                <td class="categoryTitle"><span class="space">'+space+'</span><span style="cursor:pointer" onclick="op(this,'+value.id+')">[+]</span>'+value.name+'</td>\n' +
                                '                                <td>'+value.first_char+'</td>\n' +
                                '                                <td>'+is_hot+'</td>\n' +
                                '                                <td>'+is_show+'</td>\n' +
                                '                                <td>\n' +
                                '                                    <div class="btn-group">\n' +
                                '                                        <div data-toggle="dropdown" class="btn btn-primary btn-xs dropdown-toggle">\n' +
                                '                                            操作 <span class="caret"></span>\n' +
                                '                                        </div>\n' +
                                '                                        <ul class="dropdown-menu">\n' +
                                '                                            <li>\n' +
                                '                                                <a onClick="add(\''+add_url+'\')">修改</a>\n' +
                                '                                            </li>\n' +
                                '                                            <li class="divider"></li>\n' +
                                '                                            <li><a onclick="del('+value.id+')">删除</a></li>\n' +
                                '                                        </ul>\n' +
                                '                                    </div>\n' +
                                '                                </td>\n' +
                                '                            </tr>';
                        });
                        tr_object.after(html);
                    }
                },
                error: function () {
                    layer.msg('网络错误', {icon: 2, time: 3000});
                }
            });

        } else {
            $(object).text("[+]");
            $('.class_'+pid).hide();
        }
    }
    function del(id){
        swal_del(id,"{:url('AreaDel')}", {title: '该内容'})
    }
</script>